<?php
/*
  Template Name: Sport
 */
?>
<?php
get_header();
?>
<div class="container clearfix">

    <div class="rightCol">

        <div class="sectionsAreaTags sportsTag clearfix">
            <ul>
                <?php
                $sportCatId = get_cat_ID('الرياضة');
                $newsCatId = get_cat_ID('news');
                $sportNavId = get_cat_ID('sport nav');
                the_post();
                $leagueCatId = getSportSubCat(get_the_category(), $sportNavId);
                $sportNavCategories = get_categories(array('child_of' => $sportNavId, 'hide_empty' => 0, 'orderby' => 'id'));
                if ($sportNavCategories > 5) {
                    $sportNavCategories1 = array_slice($sportNavCategories, 0, 5, TRUE);
                    $sportNavCategories2 = array_slice($sportNavCategories, 5, count($sportNavCategories), TRUE);
                }
                foreach ($sportNavCategories1 as $navCategory) {
                    $active = ($leagueCatId == $navCategory->term_id) ? 'active' : '';
                    ?>
                    <li class="<?php echo $active ?>">
                        <a href="<?php echo get_category_link($navCategory); ?>"><?php echo $navCategory->name ?></a>
                        <div class="up-triangle"></div>
                    </li>
                <?php }
                ?>
            </ul>
            <span class="openSportMenu"><span></span></span>
            <div class="sportMenu">
                <?php foreach ($sportNavCategories2 as $navCategory) { ?>
                    <a href="<?php echo get_category_link($navCategory); ?>"><?php echo $navCategory->name ?></a>
                <?php } ?>
            </div><!-- sportMenu -->
        </div><!-- sectionsAreaTags -->

        <div id="standardPhotosgallery" class="sliderkit photosgallery-std">
            <div class="sliderkit-nav">
                <div class="sliderkit-btn sliderkit-nav-btn sliderkit-nav-prev"><a rel="nofollow" href="#" title="Previous line"><span>Previous line</span></a></div>
                <div class="sliderkit-btn sliderkit-nav-btn sliderkit-nav-next"><a rel="nofollow" href="#" title="Next line"><span>Next line</span></a></div>

                <div class="sliderkit-nav-clip">
                    <ul>
                        <?php
                        $posts = get_posts(array('category__and' => array($leagueCatId, $newsCatId), 'numberposts' => 8));
                        $featuredGallery = FALSE;
                        foreach ($posts as $post) {
                            $gallery = get_post_gallery($post->ID, FALSE);
                            if ($gallery) {
                                $featuredGallery['post'] = $post;
                                $featuredGallery['gallery'] = $gallery;
                            }
                            ?>
                            <li>
                                <a href="<?php echo get_permalink($post->ID); ?>" title="[link title]"><?php echo get_the_post_thumbnail($post->ID); ?></a>
                                <span class="politicOverText">
                                    <span><?php echo $post->post_title ?></span>
                                    <span class="POVcontent"><?php echo strip_shortcodes($post->post_content); ?></span>  
                                </span><!-- politicOverText -->
                            </li>
                        <?php }
                        ?>
                    </ul>
                </div><!-- slider-nav-clip -->
            </div><!-- sliderkit-nav -->


            <?php
            if ($featuredGallery) {
                $featuredPost = $featuredGallery['post'];
                $gallery = $featuredGallery['gallery'];
//                var_dump($gallery);
//                exit;
                ?>
                <div class="sliderkit-panels">
                    <div class="sliderkit-panel">
                        <div class="sliderImage">
                            <a href="#" class="quickRead"> قراءة سريعه </a>
                            <img src="<?php echo $gallery['src'][0] ?>" alt="[Alternative text]" />
                            <h2><a href="<?php echo get_permalink($featuredPost->ID) ?>"><?php echo $featuredPost->post_title ?></a></h2>
                        </div><!-- sliderImage -->
                        <div class="sliderVideo">
                            <a href="#">
                                <img src="<?php echo $gallery['src'][1] ?>" alt="" />
                            </a>
                        </div><!-- sliderVideo -->
                        <div class="sliderVideo">
                            <a href="#">
                                <img src="<?php echo $gallery['src'][2] ?>" alt="" />
                            </a>
                        </div><!-- sliderVideo -->
                    </div><!-- sliderkit-panel -->

                </div><!-- sliderkit-panels -->
            <?php }
            ?>
        </div><!-- standardPhotosgallery -->

        <div class="homeadvsLeaderBoard"><img src="<?php bloginfo('template_url'); ?>/images/leaderBoard.jpg" alt="" /></div>

        <div class="sectionsArea">
            <div class="sectionNewsArea clearfix">
                <?php
                $articleId = get_cat_ID('article');
//                $newsCatId = get_cat_ID('news');
                echo loadSection(TRUE, $sportCatId, $articleId);
                ?>
            </div>
            <a href="#" class="seeMoreFromSection"> شاهد المزيد </a>
        </div><!-- sectionsArea -->

        <div class="newsFromSocial clearfix">
            <?php display_tweets(); ?>
        </div><!-- newsFromSocial -->

        <div class="homePhotoGalleries">
            <div class="sectionsAreaCategories clearfix">
                <h2>البومات الصور</h2>
                <ul>
                    <?php
                    $albumCatId = get_cat_ID('album');
                    $albums = get_posts(array('category__and' => array($albumCatId, $sportCatId, $leagueCatId)));
                    $counter = 1;
                    foreach ($albums as $post) {
                        ?>
                        <li class="csport">
                            <a href="#" class="fetch-album" pid="<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></a>
                            <div class="up-triangle"></div>
                        </li>
                    <?php } ?>                                                   
                </ul>
            </div><!-- sectionsAreaCategories -->

            <div class="photoAlbums" id="album-container" style="display: none;">

            </div><!-- photoAlbums -->
        </div><!-- homePhotoGalleries -->

    </div><!-- rightCol -->

    <div class="sideBar">

        <div class="importantNewsArea">
            <ul class="importantNewsTab clearfix">
                <li class="active">
                    <h2><a href="#theLatestNews">نتائج المباريات</a></h2>
                    <div class="up-triangle"></div>
                </li>
                <li>
                    <h2><a href="#mostViews">جدول الدوري</a></h2>
                    <div class="up-triangle"></div>
                </li>   
            </ul>

            <?php
            $matchResultsCat = get_cat_ID('match results');
            $resultsPost = get_posts(array('category__and' => array($matchResultsCat, $leagueCatId), 'numberposts' => 1));
            $resultsPost = $resultsPost[0];
            ?>
            <div class="matchesTime" id="theLatestNews">
                <div class="scroll-pane">
                    <span class="championName">
                        <?php echo get_the_post_thumbnail($resultsPost->ID); ?>
                        <?php echo $resultsPost->post_title; ?>
                    </span>
                    <?php echo $resultsPost->post_content; ?>
                </div><!-- scroll-pane -->
            </div><!-- matchesTime -->
            <?php
            $leagueTableCat = get_cat_ID('league table');
            $tablePost = get_posts(array('category__and' => array($leagueCatId, $leagueTableCat), 'numberposts' => 1));
            $tablePost = $tablePost[0];
            ?>
            <div class="matchesTime" id="mostViews">
                <div class="scroll-pane">
                    <span class="championName">
                        <?php echo get_the_post_thumbnail($tablePost->ID); ?>
                        <?php echo $tablePost->post_title; ?>
                    </span>
                    <div class="leagueTabel">
                        <?php echo $tablePost->post_content; ?>
                    </div>

                </div><!-- scroll-pane -->
            </div><!-- matchesTime -->

        </div><!-- imprtantNewsArea -->

        <?php get_sidebar(); ?>

    </div><!-- sideBar -->

</div><!-- container -->
<?php get_footer(); ?>
<script type="text/javascript">!function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (!d.getElementById(id)) {
            js = d.createElement(s);
            js.id = id;
            js.src = "//platform.twitter.com/widgets.js";
            fjs.parentNode.insertBefore(js, fjs);
        }
    }(document, "script", "twitter-wjs");</script>